require("./../common/bootstrap/js/bootstrap-datepicker/bootstrap-datepicker.min.js");
require("./../common/bootstrap/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js");
require("./../common/main.min.js")

var _util = require('util/util.js')
var vue = require('./../common/vue')
const { toHandlerKey } = require('vue');
const _market_service = require('service/market-service');
const _catalog_service = require("../../service/catalog-service.js");

var new_swiper = new vue({
    el: "#new_swiper",
    data: {
        arrayones: [{
            categoryid: 1,
            categoryname: "服饰穿搭",
        }, {
            categoryid: 1,
            categoryname: "服饰穿搭",
        }],
        arraytwos: [
            {
                productid: 2,
                productname: "裤子"
            }, {
                productid: 2,
                productname: "裤子"
            }],
        arrayitems: [{
            "itemid": 1,
            "productid": 2,
            "shopid": 3,
            "price": 30, //该商品基准价格,不含商品折扣和店铺折扣
            "stock": 1000,
            "description": "休闲男士时尚夏季时尚百搭工装裤",
            "src": "<image src=\"images/fu_shi_chuan_da/kuzi/100.jpg\">"
        }, {
            "itemid": 1,
            "productid": 2,
            "shopid": 3,
            "price": 30, //该商品基准价格,不含商品折扣和店铺折扣
            "stock": 1000,
            "description": "休闲男士时尚夏季时尚百搭工装裤",
            "src": "<image src=\"images/fu_shi_chuan_da/kuzi/100.jpg\">"

        }],
        selectOne: "一级分类",
        selectTwo: "二级分类",
        selectitemid: "商品名字",
        editswiperdescription: "",
        selectswiperpictrue: "",
        editstarttime: 0,
        editendtime: 0,
        editavailable: 1,
    },
    methods: {
        setitems: function () {
            console.log(this.selectTwo)
            _catalog_service.gettwoclassbyone(this.selectTwo,
                function (res) {
                    console.log(res)
                    new_swiper.arrayitems = res;
                },
                function (err) {
                    console.log(err)
                })
        },
        settwos: function () {
            console.log(this.selectOne)
            _catalog_service.gettwoclassbyone(this.selectOne,
                function (res) {
                    console.log(res)
                    new_swiper.arraytwos = res;
                },
                function (err) {
                    console.log(err)
                })
        },
        setstarttime: function () {
            new_swiper.editstarttime = $("#editstarttime").val()
        },
        setendtime: function () {
            new_swiper.editendtime = $("#editendtime").val()
        },
        addswiper: function () {
            console.log("开始更新");
            new_swiper.editavailable = new_swiper.editavailable ? 1 : 0
            console.log(new_swiper.arrayones)
            console.log(new_swiper.arraytwos)
            console.log(new_swiper.arrayitems)
            console.log(new_swiper.selectOne)
            console.log(new_swiper.selectTwo)
            console.log(new_swiper.selectitemid)
            new_swiper.selectswiperpictrue = new_swiper.selectswiperpictrue.split(".")[0];
            new_swiper.selectswiperpictrue = new_swiper.selectswiperpictrue.split("/");
            length = new_swiper.selectswiperpictrue.length;
            new_swiper.selectswiperpictrue = new_swiper.selectswiperpictrue[length - 1];
            new_swiper.selectswiperpictrue = new_swiper.selectswiperpictrue.split("\\");
            length = new_swiper.selectswiperpictrue.length;
            new_swiper.selectswiperpictrue = new_swiper.selectswiperpictrue[length - 1];
            console.log(new_swiper.editswiperdescription)
            console.log(new_swiper.selectswiperpictrue)
            console.log(new_swiper.editstarttime)
            console.log(new_swiper.editendtime)
            console.log(new_swiper.editavailable)


            _market_service.addswiper(
                {
                    slogan : new_swiper.editswiperdescription,
                    itemid: new_swiper.editswiperdescription,
                    imgsrc: new_swiper.selectswiperpictrue,
                    available: new_swiper.editavailable,
                    starttime: new_swiper.editstarttime,
                    endtime: new_swiper.editendtime
                },
                function (res) {
                    alert("添加成功")
                    console.log(res)
                },
                function (err) {
                    alert("添加失败")
                    console.log(err)
                }
            )
        },
    },
    //初始化vue对象，渲染数据
    created: function () {
        获取的购物车商品对象
        _catalog_service.getAlloneclass(
            function (res) {
                console.log(res)
                new_swiper.arrayones = res;
            },
            function (res) {
                console.log("ERROR..*..")
            }
        )
    },

})